<?php
namespace app\controller;

use app\BaseController;
use \think\facade\Request;
use \think\facade\Cache;
use \think\facade\Db;
use \think\facade\Log;
use Qcloud\Sms\SmsSingleSender;

class Index extends BaseController
{
  
  public function login()
  {
        $param = Request::param();
        $redis = Cache::store('redis');
		$data = Db::table('store_info')
				->where('uname', $param['uname'])
				->find();
		if($param['uname'] == $data['uname'] && $param['upwd'] == $data['upwd']){
		$token = bin2hex(random_bytes(32));
			$redis->set($token, 1,36000);
			$this->returnJson(200,'登录成功',['cid'=>$data['id'],'cname'=>$data['cname'],'token'=>$token]);
		}else{
			$this->returnJson(404,'账号密码输入错误',[]);
		}
  }
  // 查询二维码列表不带分页
  public function codeQrList()
	{
		$param = Request::param();
		
		$result = Db::table('code_info')
			->where('cid',$param['cid'])
			->where('status','1')
			->order('sort desc id desc')
			->whereNull('delete_time')
		    ->select();
					
		$this->returnJson(200,'操作成功',$result);
		
	}
  // 查询二维码列表带分页
	public function codeSetList()
	{
		$param = Request::param();
		$table_name = $param['table_name'];
		$map = [];
		if(isset($param['map'])){
			$map = $param['map'];
		}
		
		
		$page=$param['page'];
		$pageSize = $param['pageSize'];
		$page=($page-1)*$pageSize;
		
		$result = Db::table($table_name)
			->where('cid',$param['cid'])
			->where($map)
			->order('sort desc id desc')
			->limit($page,$pageSize)
			->whereNull('delete_time')
		    ->select();
		$count = Db::table($table_name)
					 ->where($map)
					 ->where('cid',$param['cid'])
					 ->whereNull('delete_time')
		  			 ->count();
		$data = [];
		 $data['count']=$count;
		 $data['result']=$result;				
		$this->returnJson(200,'操作成功',$data);
		
	}
	
}